class Cube extends BaseShape
{
  private PImage graphic;
  private PVector colour;
  public Cube(PImage graphic, PVector colour)
  {
    this.graphic = graphic;
    this.colour = colour;
  }
  
    final int[][] myFaces = {
        { 1, 3, 6, 5 },
        { 0, 2, 7, 4 },
        { 0, 2, 3, 1 },
        { 7, 6, 5, 4 },
        { 2, 3, 6, 7 },
        { 0, 1, 5, 4 }
    };
    final PVector[] myVertices = {
        new PVector(-1,  1, -1),
        new PVector( 1,  1, -1),
        new PVector(-1,  1,  1),
        new PVector( 1,  1,  1),
        new PVector(-1, -1, -1),
        new PVector( 1, -1, -1),
        new PVector( 1, -1,  1),
        new PVector(-1, -1,  1) 
    };
    final PVector[] myNormals = {
        new PVector( 1,  0,  0),
        new PVector(-1,  0,  0),
        new PVector( 0,  1,  0),
        new PVector( 0, -1,  0),
        new PVector( 0,  0,  1),
        new PVector( 0,  0, -1)
    };
  
    void draw ()
    {
      
        for (int f = 0; f < myFaces.length; f++)
        {
          
           beginShape();
          if (f == 4)
          {
            
              noTint();
              textureMode(NORMALIZED);
              texture(graphic);
              vertex(myVertices[myFaces[f][0]].x, myVertices[myFaces[f][0]].y, myVertices[myFaces[f][0]].z, 0, 0);
              normal(myNormals[f].x, myNormals[f].y, myNormals[f].z);
              vertex(myVertices[myFaces[f][1]].x, myVertices[myFaces[f][1]].y, myVertices[myFaces[f][1]].z, graphic.width, 0);
              normal(myNormals[f].x, myNormals[f].y, myNormals[f].z);
              vertex(myVertices[myFaces[f][2]].x, myVertices[myFaces[f][2]].y, myVertices[myFaces[f][2]].z, graphic.width, graphic.height);
              normal(myNormals[f].x, myNormals[f].y, myNormals[f].z);
              vertex(myVertices[myFaces[f][3]].x, myVertices[myFaces[f][3]].y, myVertices[myFaces[f][3]].z, 0, graphic.height);
              normal(myNormals[f].x, myNormals[f].y, myNormals[f].z);
          }
          else
          {
             
             for (int i : myFaces[f])
             {
               fill(colour.x, colour.y, colour.z);
                vertex(myVertices[i].x, myVertices[i].y, myVertices[i].z);
                normal(myNormals[f].x, myNormals[f].y, myNormals[f].z);
             }
          }
          endShape();
        }
    }
}
